#!/bin/bash
# hiiri
while true; do
echo -en "\E[6n"  # echo -e "\e[?1000h"
read -sdR CURPOS  # s-> silent
CURPOS=${CURPOS#*[}
row=${CURPOS##*;}; let row--
col=${CURPOS%%;*}; let col--
echo $row'   '$col
echo -en "\e[?1000h"; read -n 6 -s -t0.1 a ; echo -en "\e[?1001h"; [[ $a ]] && echo 'hiirtä painettu'
done

tput cup 5 5 # tämä on testauksen vuoksi, että näytölle tulisi jotain mitä osaa odottaa
exec < /dev/tty
oldstty=$(stty -g)
stty raw -echo min 0
# on my system, the following line can be replaced by the line below it
echo -en "\033[6n" > /dev/tty
tput u7 > /dev/tty    # when TERM=xterm (and relatives) # alussa
IFS=';' read -r -d R -a pos; IFS=' '
stty $oldstty
# change from one-based to zero based so they work with: tput cup $row $col
row=$((${pos[0]:2} - 1))    # strip off the esc-[
col=$((${pos[1]} - 1))
echo $row'   '$col # ja tämä on taas testauksaen takia
 



